﻿/* Nibiru Studio Engine Version [1062] */
#include "SceneLoad.h"
#include "EyeManager.h"


ENGINE_NAMESPACE_BEGIN

IMPLEMENT_CLASS(SceneLoad)
IMPLEMENT_RTTI_CUSTOM(SceneLoad, NComponent)

//ENUM_BEGIN(LabelType, LabelType)
// add your enum
// Display Name, Enum Type Name
// ENUM(Left, LEFT)
//ENUM_END


REFLECTION_BEGIN(SceneLoad)
// add your variable reflection property
//Enum Class Name, Display Name In Editor, Variable Name In Class, flags default is 0
//ENUM_PROPERTY(LabelType, Type, m_LabelType, 0)
//PROPERTY(Bold, m_IsBold, 0)
//PROPERTY(Rotate, m_EnableRotate, 0)
//FUNCTION(OnButtonClick, SceneLoad, OnClick)

REFLECTION_END


void SceneLoad::Start()
{
    m_pEyeManager = EyeManager::instance();
    //
    m_textMessage = NActorManager::GetActor("text_load_message")->GetComponent<NLabel>();
    m_delayStart = 0;
}

void SceneLoad::Update()
{
    if (NInput::GetKeyDown(KeyboardKeys::Android_Back))
    {
        NDebug::Log("%s android back quit", EYE_TAG);
        m_pEyeManager->stop();
        NApplication::Quit();
    }
    doStart();
    doSwitchCalib();
}

void SceneLoad::OnDestroy()
{
	// When the component deleted
}

void SceneLoad::PostEditChangeProperty(std::string& propertyName)
{
	// Variable Property changed in Editor
}

void SceneLoad::Serialize(Archive& ar)
{
	Super::Serialize(ar);
	// SERIALIZE(m_EnableRotate);
}

void SceneLoad::LateDeserialize(Archive& ar)
{
	// After all Serialize are executed
	Super::LateDeserialize(ar);
}

void SceneLoad::doStart()
{
    if (m_delayStart < 0)
    {
        return;
    }
    m_delayStart++;
    if (m_delayStart >= 20)
    {
        m_delayStart = -1;
        ServiceResult serviceResult = m_pEyeManager->start();
        NDebug::Log("%s start code=%d", EYE_TAG, serviceResult.code);
        if (serviceResult.code != 0)
        {
            NDebug::Log("%s start error, %s", EYE_TAG, serviceResult.toString().c_str());
            m_textMessage->SetText(serviceResult.toString());
            return;
        }
        m_delaySwitch = 0;
    }
}

// 跳转页面
void SceneLoad::doSwitchCalib()
{
    if (m_delaySwitch < 0)
    {
        return;
    }
    m_delaySwitch++;
    if (m_delaySwitch >= 90)
    {
        m_delaySwitch = -1;
        NDebug::Log("%s switch to calib scene", EYE_TAG);
        NLevelManager::LoadLevel("scene_calib.nscene");
    }
}

ENGINE_NAMESPACE_END
